/**
 * output package name
 */
package com.kingdee.eas.custom.bscc.report.client;

import java.awt.event.ActionEvent;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.prefs.Preferences;

import javax.swing.event.TreeSelectionEvent;
import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;

import org.apache.log4j.Logger;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.ctrl.kdf.form.Page;
import com.kingdee.bos.ctrl.kdf.headfootdesigner.HeadFootModel;
import com.kingdee.bos.ctrl.kdf.headfootdesigner.HeadFootParser;
import com.kingdee.bos.ctrl.kdf.table.IColumn;
import com.kingdee.bos.ctrl.kdf.table.IRow;
import com.kingdee.bos.ctrl.kdf.table.KDTable;
import com.kingdee.bos.ctrl.kdf.table.print.IRequestTableData;
import com.kingdee.bos.ctrl.kdf.table.print.MultiPrint;
import com.kingdee.bos.ctrl.kdf.util.style.StyleAttributes;
import com.kingdee.bos.ctrl.kdf.util.style.Styles;
import com.kingdee.bos.ctrl.swing.tree.DefaultKingdeeTreeNode;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.dao.query.IQueryExecutor;
import com.kingdee.bos.dao.query.QueryExecutorFactory;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SorterItemCollection;
import com.kingdee.bos.metadata.entity.SorterItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.ui.face.CoreUIObject;
import com.kingdee.bos.ui.face.IUIObject;
import com.kingdee.bos.ui.face.IUIWindow;
import com.kingdee.bos.ui.face.UIException;
import com.kingdee.bos.ui.face.UIFactory;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.eas.base.core.Constants;
import com.kingdee.eas.base.core.fm.ContextHelperFactory;
import com.kingdee.eas.basedata.assistant.AccountBankInfo;
import com.kingdee.eas.basedata.assistant.AccountBankPropertyEnum;
import com.kingdee.eas.basedata.assistant.AccountPropertyInfo;
import com.kingdee.eas.basedata.assistant.BankInfo;
import com.kingdee.eas.basedata.assistant.CurrencyInfo;
import com.kingdee.eas.basedata.org.CompanyOrgUnitInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.common.client.OprtState;
import com.kingdee.eas.common.client.SysContext;
import com.kingdee.eas.common.client.UIContext;
import com.kingdee.eas.fi.cas.client.AbstractCasSubsidiaryLedgerHandler;
import com.kingdee.eas.fi.cas.client.CasSubsidiaryLedgerFilterParam;
import com.kingdee.eas.fm.common.FMHelper;
import com.kingdee.eas.fm.common.client.FMClientHelper;
import com.kingdee.eas.fm.common.client.FMFilterBaseUI;
import com.kingdee.eas.fm.fs.FSException;
import com.kingdee.eas.fm.fs.InnerAccountCollection;
import com.kingdee.eas.fm.fs.InnerAccountInfo;
import com.kingdee.eas.fm.fs.SubsidiaryLedgerFactory;
import com.kingdee.eas.fm.fs.SubsidiaryLedgerInfo;
import com.kingdee.eas.fm.fs.client.AbstractSubsidiaryLedgerHandler;
import com.kingdee.eas.fm.fs.client.FSAnalysisHandlerFactory;
import com.kingdee.eas.fm.fs.client.FSClientHelper;
import com.kingdee.eas.fm.fs.client.SubsidiaryLedgerFilterParam;
import com.kingdee.eas.fm.fs.client.SubsidiaryPrintSettingUI;
import com.kingdee.eas.util.SysUtil;
import com.kingdee.eas.util.client.EASResource;
import com.kingdee.eas.util.client.MsgBox;

/**
 * output class name
 */
public class SubsidiaryLedgerUI extends AbstractSubsidiaryLedgerUI
{
    class DoPrintThreadPre extends Thread
    {
                public void run()
                {

/* 707*/            if(multiPrint != null)
/* 708*/                if(!doPrint)
/* 709*/                    multiPrint.preview();

/* 711*/                else/* 711*/                    multiPrint.print();

/* 715*/            tblMain.setPrintManager(tablePrint.getPrintManager());
///* 716*/            SubsidiaryLedgerUI.this.multiPrint.savePrintSetting();
                }
                private MultiPrint multiPrint;
                private boolean doPrint;
                final SubsidiaryLedgerUI this$0;
                public DoPrintThreadPre(MultiPrint multiPrint, boolean doPrint)
                {
/* <-MISALIGNED-> */ /* 701*/            this$0 = SubsidiaryLedgerUI.this;
///* <-MISALIGNED-> */ /* 701*/            super();
/* <-MISALIGNED-> */ /* 702*/            this.multiPrint = multiPrint;
/* <-MISALIGNED-> */ /* 703*/            this.doPrint = doPrint;
                }
    }
            public SubsidiaryLedgerUI()
                throws Exception
            {
/* <-MISALIGNED-> */ /*  99*/        resourcePath = "com.kingdee.eas.fm.fs.client.SubsidiaryLedgerResource";
/* <-MISALIGNED-> */ /* 113*/        tablePrint = null;
/* <-MISALIGNED-> */ /* 499*/        refreshTree = false;
/* <-MISALIGNED-> */ /* 722*/        doPrint = new Runnable() {
                    public void run()
                    {
/* <-MISALIGNED-> */ /* 725*/                if(multiPrint != null)
/* <-MISALIGNED-> */ /* 726*/                    multiPrint.preview();
                    }
                    final SubsidiaryLedgerUI this$0;
                    
                    { 
/* <-MISALIGNED-> */ /* 723*/               
                    	this$0 = SubsidiaryLedgerUI.this;
/* <-MISALIGNED-> */ /* 723*/               
                    }
        }
;
/* <-MISALIGNED-> */ /* 119*/        tablePrint = new KDTable();
            }
            public void onShow()
                throws Exception
            {
/* <-MISALIGNED-> */ /* 124*/        super.onShow();
/* <-MISALIGNED-> */ /* 125*/        treeList.requestFocus();
            }
            protected void execQuery()
                throws BOSException
            {
/* <-MISALIGNED-> */ /* 132*/        SubsidiaryLedgerFilterParam param = (SubsidiaryLedgerFilterParam)getFilterParam();
/* <-MISALIGNED-> */ /* 133*/        AbstractSubsidiaryLedgerHandler handler = FSAnalysisHandlerFactory.getHandler(param);
/* <-MISALIGNED-> */ /* 136*/        String datePeriod = "";
/* <-MISALIGNED-> */ /* 137*/        if(!param.isByDay())
/* <-MISALIGNED-> */ /* 138*/            datePeriod = (new StringBuilder()).append(param.getBeginYear()).append("-").append(param.getBeginMonth()).append(" - ").append(param.getEndYear()).append("-").append(param.getEndMonth()).toString();
/* <-MISALIGNED-> */ /* 141*/        else
/* <-MISALIGNED-> */ /* 141*/            datePeriod = (new StringBuilder()).append(Constants.FORMAT_DAY.format(param.getFromDate())).append(" - ").append(Constants.FORMAT_DAY.format(param.getToDate())).toString();
/* <-MISALIGNED-> */ /* 144*/        txtPeriodRange.setText(datePeriod);
/* <-MISALIGNED-> */ /* 146*/        tblMain.checkParsed();
/* <-MISALIGNED-> */ /* 147*/        tblMain.getStyleAttributes().setLocked(true);
/* <-MISALIGNED-> */ /* 148*/        tblMain.getSelectManager().setSelectMode(10);
/* <-MISALIGNED-> */ /* 151*/        try
                {
/* <-MISALIGNED-> */ /* 151*/            handler.initTree(treeList, param);
                }
/* <-MISALIGNED-> */ /* 152*/        catch(EASBizException e)
                {
/* <-MISALIGNED-> */ /* 153*/            logger.error(e.getMessage(), e);
/* <-MISALIGNED-> */ /* 154*/            SysUtil.abort();
                }
/* <-MISALIGNED-> */ /* 157*/        DefaultKingdeeTreeNode node = null;
/* <-MISALIGNED-> */ /* 158*/        node = (DefaultKingdeeTreeNode)getUIContext().get("DefaultTreeNode");
/* <-MISALIGNED-> */ /* 160*/        if(node != null)
                {
/* <-MISALIGNED-> */ /* 161*/            setSelectionNode(node);
/* <-MISALIGNED-> */ /* 162*/            getUIContext().put("DefaultTreeNode", null);
                } else
                {
/* <-MISALIGNED-> */ /* 164*/            FSClientHelper.setFirstInnerAcctNodeSelected(treeList);
                }
            }
            private void setSelectionNode(DefaultKingdeeTreeNode node)
            {
/* <-MISALIGNED-> */ /* 172*/        InnerAccountInfo sumInner = (InnerAccountInfo)node.getUserObject();
/* <-MISALIGNED-> */ /* 173*/        int height = treeList.getRowCount();
/* <-MISALIGNED-> */ /* 174*/        for(int i = 1; i < height; i++)
                {
/* <-MISALIGNED-> */ /* 175*/            TreePath tp = treeList.getPathForRow(i);
/* <-MISALIGNED-> */ /* 176*/            if(tp != null)
                    {
/* <-MISALIGNED-> */ /* 180*/                DefaultKingdeeTreeNode tn = (DefaultKingdeeTreeNode)tp.getLastPathComponent();
/* <-MISALIGNED-> */ /* 182*/                setSelectionNode(sumInner.getId().toString(), tn);
                    }
                }
            }
            private void setSelectionNode(String srcInnerAcctId, DefaultKingdeeTreeNode node)
            {
/* <-MISALIGNED-> */ /* 188*/        boolean isMatched = false;
/* <-MISALIGNED-> */ /* 189*/        if(node.isLeaf())
                {
/* <-MISALIGNED-> */ /* 190*/            Object obj = node.getUserObject();
/* <-MISALIGNED-> */ /* 191*/            if(obj instanceof InnerAccountInfo)
                    {
/* <-MISALIGNED-> */ /* 192*/                InnerAccountInfo info = (InnerAccountInfo)obj;
/* <-MISALIGNED-> */ /* 193*/                if(srcInnerAcctId.equals(info.getId().toString()))
                        {
/* <-MISALIGNED-> */ /* 194*/                    treeList.setSelectionNode(node);
/* <-MISALIGNED-> */ /* 195*/                    isMatched = true;
/* <-MISALIGNED-> */ /* 196*/                    return;
                        }
                    }
                }
/* <-MISALIGNED-> */ /* 200*/        int childCount = node.getChildCount();
/* <-MISALIGNED-> */ /* 202*/        for(int i = 0; i < childCount && !isMatched; i++)
                {
/* <-MISALIGNED-> */ /* 206*/            DefaultKingdeeTreeNode childNode = (DefaultKingdeeTreeNode)node.getChildAt(i);
/* <-MISALIGNED-> */ /* 208*/            setSelectionNode(srcInnerAcctId, childNode);
                }
            }
            public void parseAcctNumber(DefaultKingdeeTreeNode node, Set acctNumberSet)
            {
/* <-MISALIGNED-> */ /* 216*/        int childCount = node.getChildCount();
/* <-MISALIGNED-> */ /* 217*/        if(childCount == 0)
/* <-MISALIGNED-> */ /* 218*/            return;
/* <-MISALIGNED-> */ /* 222*/        for(int j = 0; j < childCount; j++)
                {
/* <-MISALIGNED-> */ /* 223*/            DefaultKingdeeTreeNode childNode = (DefaultKingdeeTreeNode)treeList.getModel().getChild(node, j);
/* <-MISALIGNED-> */ /* 226*/            if(childNode.getUserObject() instanceof InnerAccountInfo)
                    {
/* <-MISALIGNED-> */ /* 227*/                InnerAccountInfo innerAcct = (InnerAccountInfo)childNode.getUserObject();
/* <-MISALIGNED-> */ /* 228*/                acctNumberSet.add(innerAcct.getNumber());
/* <-MISALIGNED-> */ /* 229*/                continue;
                    }
/* <-MISALIGNED-> */ /* 231*/            if(childNode.getUserObject() instanceof AccountBankInfo)
                    {
/* <-MISALIGNED-> */ /* 232*/                AccountBankInfo bankAcct = (AccountBankInfo)childNode.getUserObject();
/* <-MISALIGNED-> */ /* 233*/                acctNumberSet.add(bankAcct.getNumber());
/* <-MISALIGNED-> */ /* 234*/                continue;
                    }
/* <-MISALIGNED-> */ /* 235*/            for(int k = 0; k < node.getChildCount(); k++)
/* <-MISALIGNED-> */ /* 236*/                parseAcctNumber((DefaultKingdeeTreeNode)node.getChildAt(k), acctNumberSet);
                }
            }
            public FMFilterBaseUI getFilterUI()
                throws Exception
            {
/* <-MISALIGNED-> */ /* 250*/        if(filterUI == null)
/* <-MISALIGNED-> */ /* 251*/            filterUI = new SubsidiaryLedgerFilterUI();
/* <-MISALIGNED-> */ /* 254*/        return filterUI;
            }
            protected void treeList_valueChanged(TreeSelectionEvent e)
                throws Exception
            {
/* <-MISALIGNED-> */ /* 261*/        super.treeList_valueChanged(e);
/* <-MISALIGNED-> */ /* 266*/        fillTableData();
/* <-MISALIGNED-> */ /* 268*/        balanceMap = null;
            }
            private void fillTableData()
                throws EASBizException, BOSException, SQLException
            {
/* <-MISALIGNED-> */ /* 278*/        tblMain.removeRows();
/* <-MISALIGNED-> */ /* 280*/        TreePath path = treeList.getSelectionPath();
/* <-MISALIGNED-> */ /* 281*/        if(path == null)
/* <-MISALIGNED-> */ /* 282*/            return;
/* <-MISALIGNED-> */ /* 285*/        DefaultKingdeeTreeNode node = (DefaultKingdeeTreeNode)path.getLastPathComponent();
/* <-MISALIGNED-> */ /* 287*/        if(node == null)
/* <-MISALIGNED-> */ /* 288*/            return;
/* <-MISALIGNED-> */ /* 295*/        Object obj = node.getUserObject();
/* <-MISALIGNED-> */ /* 296*/        if(obj == null)
                {
/* <-MISALIGNED-> */ /* 297*/            tblMain.removeRows();
/* <-MISALIGNED-> */ /* 298*/            return;
                }
/* <-MISALIGNED-> */ /* 301*/        Set acctNumberSet = new HashSet();
/* <-MISALIGNED-> */ /* 303*/        if(obj != null && (obj instanceof InnerAccountInfo))
                {
/* <-MISALIGNED-> */ /* 304*/            InnerAccountInfo innerAcct = (InnerAccountInfo)obj;
/* <-MISALIGNED-> */ /* 305*/            acctNumberSet.add(innerAcct.getNumber());
                }
/* <-MISALIGNED-> */ /* 309*/        if(obj != null && (obj instanceof CompanyOrgUnitInfo))
/* <-MISALIGNED-> */ /* 310*/            parseAcctNumber(node, acctNumberSet);
/* <-MISALIGNED-> */ /* 312*/        if(obj != null && (obj instanceof AccountBankPropertyEnum))
/* <-MISALIGNED-> */ /* 313*/            parseAcctNumber(node, acctNumberSet);
/* <-MISALIGNED-> */ /* 315*/        if(obj != null && (obj instanceof AccountPropertyInfo))
/* <-MISALIGNED-> */ /* 316*/            parseAcctNumber(node, acctNumberSet);
/* <-MISALIGNED-> */ /* 319*/        if(acctNumberSet.size() == 0)
                {
/* <-MISALIGNED-> */ /* 320*/            return;
                } else
                {
/* <-MISALIGNED-> */ /* 323*/            fillTable(tblMain, acctNumberSet);
/* <-MISALIGNED-> */ /* 324*/            return;
                }
            }
            private void fillTable(KDTable table, Set acctNumberSet)
                throws BOSException, EASBizException, SQLException
            {
/* <-MISALIGNED-> */ /* 328*/        String acctNumbers = TransferSetToString(acctNumberSet);
/* <-MISALIGNED-> */ /* 331*/        CompanyOrgUnitInfo chCompany = ContextHelperFactory.getRemoteInstance().getCurrentCompany();
/* <-MISALIGNED-> */ /* 334*/        BOSUuid currencyId = null;
/* <-MISALIGNED-> */ /* 335*/        EntityViewInfo ev = (EntityViewInfo)mainQuery.clone();
/* <-MISALIGNED-> */ /* 336*/        FilterInfo filter = ev.getFilter();
/* <-MISALIGNED-> */ /* 338*/        CurrencyInfo currency = (CurrencyInfo)cboCurrency.getSelectedItem();
/* <-MISALIGNED-> */ /* 339*/        currencyId = currency.getId();
/* <-MISALIGNED-> */ /* 340*/        filter.getFilterItems().add(new FilterItemInfo("currency.id", currencyId));
/* <-MISALIGNED-> */ /* 342*/        filter.getFilterItems().add(new FilterItemInfo("innerAccount.number", acctNumberSet, CompareType.INCLUDE));
/* <-MISALIGNED-> */ /* 363*/        SorterItemCollection sorter = ev.getSorter();
/* <-MISALIGNED-> */ /* 364*/        sorter.add(new SorterItemInfo("company.id"));
/* <-MISALIGNED-> */ /* 365*/        sorter.add(new SorterItemInfo("date"));
/* <-MISALIGNED-> */ /* 369*/        sorter.add(new SorterItemInfo("createTime"));
/* <-MISALIGNED-> */ /* 370*/        sorter.add(new SorterItemInfo("seq"));
/* <-MISALIGNED-> */ /* 371*/        sorter.add(new SorterItemInfo("billNumber"));
/* <-MISALIGNED-> */ /* 373*/        sorter.add(new SorterItemInfo("debitAmount"));
/* <-MISALIGNED-> */ /* 375*/        IQueryExecutor exec = QueryExecutorFactory.getRemoteInstance(mainQueryPK);
/* <-MISALIGNED-> */ /* 377*/        exec.setObjectView(ev);
/* <-MISALIGNED-> */ /* 378*/        com.kingdee.jdbc.rowset.IRowSet rs = exec.executeQuery();
/* <-MISALIGNED-> */ /* 380*/         SubsidiaryLedgerFilterParam param = (SubsidiaryLedgerFilterParam)getFilterParam();
/* <-MISALIGNED-> */ /* 133*/        AbstractSubsidiaryLedgerHandler handler = FSAnalysisHandlerFactory.getHandler(param);
/* <-MISALIGNED-> */ /* 383*/        handler.fillData3(mainQueryPK, table, rs, param, chCompany.getNumber(), currencyId, acctNumbers);
            }
            private String TransferSetToString(Set acctNumberSet)
            {
/* <-MISALIGNED-> */ /* 395*/        String acctNumbers = new String();
/* <-MISALIGNED-> */ /* 396*/        Iterator iter = acctNumberSet.iterator();
/* <-MISALIGNED-> */ /* 397*/        for(int i = 0; iter.hasNext(); i++)
                {
/* <-MISALIGNED-> */ /* 399*/            String accountNumber = (String)iter.next();
/* <-MISALIGNED-> */ /* 400*/            if(i == 0)
/* <-MISALIGNED-> */ /* 401*/                acctNumbers = (new StringBuilder()).append(acctNumbers).append(accountNumber).toString();
/* <-MISALIGNED-> */ /* 403*/            else
/* <-MISALIGNED-> */ /* 403*/                acctNumbers = (new StringBuilder()).append(acctNumbers).append(",").append(accountNumber).toString();
                }
/* <-MISALIGNED-> */ /* 407*/        return acctNumbers.toString();
            }
            private void fillTable(KDTable table, String acctNumbers, InnerAccountCollection innerAcctColl)
                throws BOSException, EASBizException, SQLException
            {
/* <-MISALIGNED-> */ /* 425*/        Set acctSet = new HashSet();
/* <-MISALIGNED-> */ /* 426*/        if(acctNumbers.indexOf(",") == -1)
                {
/* <-MISALIGNED-> */ /* 427*/            acctSet.add(acctNumbers);
                } else
                {
/* <-MISALIGNED-> */ /* 429*/            String acctArray[] = acctNumbers.split(",");
/* <-MISALIGNED-> */ /* 430*/            for(int i = 0; i < acctArray.length; i++)
/* <-MISALIGNED-> */ /* 431*/                acctSet.add(acctArray[i]);
                }
/* <-MISALIGNED-> */ /* 436*/        CompanyOrgUnitInfo chCompany = ContextHelperFactory.getRemoteInstance().getCurrentCompany();
/* <-MISALIGNED-> */ /* 439*/        BOSUuid currencyId = null;
/* <-MISALIGNED-> */ /* 440*/        EntityViewInfo ev = (EntityViewInfo)mainQuery.clone();
/* <-MISALIGNED-> */ /* 441*/        FilterInfo filter = ev.getFilter();
/* <-MISALIGNED-> */ /* 443*/        CurrencyInfo currency = (CurrencyInfo)cboCurrency.getSelectedItem();
/* <-MISALIGNED-> */ /* 444*/        currencyId = currency.getId();
/* <-MISALIGNED-> */ /* 445*/        filter.getFilterItems().add(new FilterItemInfo("currency.id", currencyId));
/* <-MISALIGNED-> */ /* 447*/        filter.getFilterItems().add(new FilterItemInfo("innerAccount.number", acctSet, CompareType.INCLUDE));
/* <-MISALIGNED-> */ /* 451*/        SorterItemCollection sorter = ev.getSorter();
/* <-MISALIGNED-> */ /* 452*/        sorter.add(new SorterItemInfo("company.id"));
/* <-MISALIGNED-> */ /* 453*/        sorter.add(new SorterItemInfo("date"));
/* <-MISALIGNED-> */ /* 457*/        sorter.add(new SorterItemInfo("createTime"));
/* <-MISALIGNED-> */ /* 458*/        sorter.add(new SorterItemInfo("seq"));
/* <-MISALIGNED-> */ /* 459*/        sorter.add(new SorterItemInfo("billNumber"));
/* <-MISALIGNED-> */ /* 461*/        IQueryExecutor exec = QueryExecutorFactory.getRemoteInstance(mainQueryPK);
/* <-MISALIGNED-> */ /* 463*/        exec.setObjectView(ev);
/* <-MISALIGNED-> */ /* 464*/        com.kingdee.jdbc.rowset.IRowSet rs = exec.executeQuery();
/* <-MISALIGNED-> */ /* 466*/        SubsidiaryLedgerFilterParam param = (SubsidiaryLedgerFilterParam)getFilterParam();
/* <-MISALIGNED-> */ /* 468*/        AbstractSubsidiaryLedgerHandler handler = FSAnalysisHandlerFactory.getHandler(param);
/* <-MISALIGNED-> */ /* 471*/        if(balanceMap == null)
/* <-MISALIGNED-> */ /* 472*/            balanceMap = handler.getBalanceMap(mainQueryPK, table, rs, param, chCompany.getNumber(), currencyId, acctNumbers, innerAcctColl);
/* <-MISALIGNED-> */ /* 477*/        handler.fillData3(mainQueryPK, table, rs, param, chCompany.getNumber(), currencyId, acctNumbers, innerAcctColl, balanceMap);
            }
            
            protected void cboCurrency_actionPerformed(ActionEvent e)
                throws Exception
            {
/* <-MISALIGNED-> */ /* 487*/        super.cboCurrency_actionPerformed(e);
/* <-MISALIGNED-> */ /* 488*/        treeList_valueChanged(null);
            }
            private void checkClearHourse()
                throws Exception
            {
///* <-MISALIGNED-> */ /* 495*/        FSClientHelper.checkClearingHouseCompany();
            }
            public void onLoad()
                throws Exception
            {
///* <-MISALIGNED-> */ /* 502*/        BankInfo bankInfo = FSClientHelper.getClearingHouse();
///* <-MISALIGNED-> */ /* 503*/        if(bankInfo.getSettleDate() == null)
                {
///* <-MISALIGNED-> */ /* 505*/            MsgBox.showWarning(this, EASResource.getString("com.kingdee.eas.fm.fs.FSClientResource", "ClearingHouseNotUsed"));
///* <-MISALIGNED-> */ /* 507*/            SysUtil.abort();
                }
/* <-MISALIGNED-> */ /* 510*/        treeView.setShowControlPanel(true);
///* <-MISALIGNED-> */ /* 511*/        CompanyOrgUnitInfo company = ContextHelperFactory.getRemoteInstance().getCurrentCompany();
///* <-MISALIGNED-> */ /* 515*/        FMClientHelper.initCurrency(cboCurrency);
///* <-MISALIGNED-> */ /* 518*/        Object currency = getUIContext().get("currency");
///* <-MISALIGNED-> */ /* 519*/        if(currency != null)
///* <-MISALIGNED-> */ /* 520*/            cboCurrency.setSelectedItem(currency);
///* <-MISALIGNED-> */ /* 522*/        else
/////* <-MISALIGNED-> */ /* 522*/            FMClientHelper.setSelectObject(cboCurrency, ContextHelperFactory.getRemoteInstance().getCompanyBaseCurrency(company));
/* <-MISALIGNED-> */ /* 526*/        super.onLoad();
/* <-MISALIGNED-> */ /* 527*/        btnQuery.setText(resHelper.getString("ActionQuery.SHORT_DESCRIPTION"));
/* <-MISALIGNED-> */ /* 529*/        btnPrint.setText(resHelper.getString("ActionPrint.SHORT_DESCRIPTION"));
/* <-MISALIGNED-> */ /* 531*/        btnPrintPre.setText(resHelper.getString("ActionPrintPre.SHORT_DESCRIPTION"));
/* <-MISALIGNED-> */ /* 533*/        btnRefresh.setText(resHelper.getString("ActionRefresh.NAME"));
/* <-MISALIGNED-> */ /* 535*/        Preferences pref = Preferences.userNodeForPackage(getClass());
/* <-MISALIGNED-> */ /* 536*/        isPrintAll = pref.getBoolean("isPrintAll", false);
/* <-MISALIGNED-> */ /* 538*/        isPaging = pref.getBoolean("isPaging", true);
/* <-MISALIGNED-> */ /* 548*/        refreshTree = true;
            }
            public static void showSubsidiaryLedgerUI(IUIObject ui, SubsidiaryLedgerFilterParam param, DefaultKingdeeTreeNode node, CurrencyInfo curInfo)
                throws UIException
            {
/* <-MISALIGNED-> */ /* 558*/        UIContext uiContext = new UIContext(ui);
/* <-MISALIGNED-> */ /* 560*/        uiContext.put("isDirectShow", Boolean.TRUE);
/* <-MISALIGNED-> */ /* 562*/        uiContext.put("filterParam", param);
/* <-MISALIGNED-> */ /* 563*/        uiContext.put("DefaultTreeNode", node);
/* <-MISALIGNED-> */ /* 564*/        uiContext.put("currency", curInfo);
/* <-MISALIGNED-> */ /* 567*/        IUIWindow uiWindow = UIFactory.createUIFactory("com.kingdee.eas.base.uiframe.client.UINewTabFactory").create("com.kingdee.eas.custom.bscc.report.client.SubsidiaryLedgerUI", uiContext, null, OprtState.VIEW);
/* <-MISALIGNED-> */ /* 570*/        uiWindow.show();
            }
            protected void initWorkButton()
            {
/* <-MISALIGNED-> */ /* 581*/        super.initWorkButton();
/* <-MISALIGNED-> */ /* 583*/        actionViewSettlementBill.putValue("SmallIcon", EASResource.getIcon("imgTbtn_linkviewbill"));
/* <-MISALIGNED-> */ /* 586*/        actionPrintSetting.putValue("SmallIcon", EASResource.getIcon("imgTbtn_distributelog"));
            }
            public void actionViewSettlementBill_actionPerformed(ActionEvent e)
                throws Exception
            {
/* <-MISALIGNED-> */ /* 598*/        checkSelected();
/* <-MISALIGNED-> */ /* 599*/        int i = tblMain.getSelectManager().getActiveRowIndex();
/* <-MISALIGNED-> */ /* 601*/        String id = (String)tblMain.getRow(i).getCell("id").getValue();
/* <-MISALIGNED-> */ /* 602*/        if(FMHelper.isEmpty(id))
                {
/* <-MISALIGNED-> */ /* 603*/            MsgBox.showInfo(this, EASResource.getString(resourcePath, "SelectValidRecord"));
/* <-MISALIGNED-> */ /* 605*/            return;
                }
/* <-MISALIGNED-> */ /* 607*/        SubsidiaryLedgerInfo info = SubsidiaryLedgerFactory.getRemoteInstance().getSubsidiaryLedgerInfo(new ObjectUuidPK(BOSUuid.read(id)));
/* <-MISALIGNED-> */ /* 611*/        BOSUuid bosUuid = info.getBillId();
/* <-MISALIGNED-> */ /* 612*/        if(bosUuid == null)
                {
/* <-MISALIGNED-> */ /* 613*/            MsgBox.showInfo(this, EASResource.getString(resourcePath, "SelectValidRecord"));
/* <-MISALIGNED-> */ /* 615*/            return;
                }
/* <-MISALIGNED-> */ /* 617*/        String billId = bosUuid.toString();
///* <-MISALIGNED-> */ /* 618*/        if(billId != null)
///* <-MISALIGNED-> */ /* 619*/            FMClientHelper.viewDetailBill(this, billId, ContextHelperFactory.getRemoteInstance().getCurrentCompany());
            }
            protected KDTable getMainTable()
            {
/* <-MISALIGNED-> */ /* 632*/        return tblMain;
            }
            protected void preparePrintPageHeader(HeadFootModel headerModel)
            {
/* <-MISALIGNED-> */ /* 641*/        TreePath path = treeList.getSelectionPath();
/* <-MISALIGNED-> */ /* 642*/        if(path == null)
/* <-MISALIGNED-> */ /* 643*/            return;
/* <-MISALIGNED-> */ /* 646*/        DefaultKingdeeTreeNode node = (DefaultKingdeeTreeNode)path.getLastPathComponent();
/* <-MISALIGNED-> */ /* 648*/        if(node == null)
/* <-MISALIGNED-> */ /* 649*/            return;
/* <-MISALIGNED-> */ /* 651*/        if(node.isRoot())
/* <-MISALIGNED-> */ /* 652*/            return;
/* <-MISALIGNED-> */ /* 654*/        Object obj = node.getUserObject();
/* <-MISALIGNED-> */ /* 655*/        if(obj == null)
/* <-MISALIGNED-> */ /* 656*/            return;
/* <-MISALIGNED-> */ /* 660*/        if(obj != null && (obj instanceof CompanyOrgUnitInfo))
/* <-MISALIGNED-> */ /* 661*/            return;
/* <-MISALIGNED-> */ /* 663*/        if(obj != null && (obj instanceof AccountBankPropertyEnum))
/* <-MISALIGNED-> */ /* 664*/            return;
/* <-MISALIGNED-> */ /* 668*/        String inAcctString = "";
/* <-MISALIGNED-> */ /* 669*/        if(obj != null && (obj instanceof InnerAccountInfo))
                {
/* <-MISALIGNED-> */ /* 670*/            InnerAccountInfo innerAcct = (InnerAccountInfo)obj;
/* <-MISALIGNED-> */ /* 671*/            inAcctString = (new StringBuilder()).append(innerAcct.getNumber()).append("-").append(innerAcct.getName()).toString();
                }
/* <-MISALIGNED-> */ /* 675*/        if(inAcctString == null)
                {
/* <-MISALIGNED-> */ /* 676*/            return;
                } else
                {
/* <-MISALIGNED-> */ /* 678*/            String headString = inAcctString;
/* <-MISALIGNED-> */ /* 679*/            headerModel.addRow(headString, Styles.getDefaultSA());
/* <-MISALIGNED-> */ /* 680*/            super.preparePrintPageHeader(headerModel);
/* <-MISALIGNED-> */ /* 681*/            return;
                }
            }
            public void actionPrint_actionPerformed(ActionEvent e)
                throws Exception
            {
/* <-MISALIGNED-> */ /* 684*/        initMultiPrint();
/* <-MISALIGNED-> */ /* 685*/        DoPrintThreadPre doP = new DoPrintThreadPre(multiPrint, true);
/* <-MISALIGNED-> */ /* 686*/        doP.start();
            }
            public void actionPrintPre_actionPerformed(ActionEvent e)
                throws Exception
            {
/* <-MISALIGNED-> */ /* 690*/        initMultiPrint();
/* <-MISALIGNED-> */ /* 691*/        DoPrintThreadPre doP = new DoPrintThreadPre(multiPrint, false);
/* <-MISALIGNED-> */ /* 692*/        doP.start();
            }
            public void actionPrintSetting_actionPerformed(ActionEvent e)
                throws Exception
            {
/* <-MISALIGNED-> */ /* 734*/        UIContext uiCtx = new UIContext(this);
/* <-MISALIGNED-> */ /* 735*/        uiCtx.put("Owner", this);
/* <-MISALIGNED-> */ /* 736*/        IUIWindow printSetUI = UIFactory.createUIFactory("com.kingdee.eas.base.uiframe.client.UIModelDialogFactory").create("com.kingdee.eas.fm.fs.client.SubsidiaryPrintSettingUI", uiCtx);
/* <-MISALIGNED-> */ /* 738*/        printSetUI.show();
/* <-MISALIGNED-> */ /* 739*/        SubsidiaryPrintSettingUI printSetUIObj = (SubsidiaryPrintSettingUI)printSetUI.getUIObject();
/* <-MISALIGNED-> */ /* 741*/        if(printSetUIObj.isOK())
                {
/* <-MISALIGNED-> */ /* 742*/            isPrintAll = printSetUIObj.isPrintAll();
/* <-MISALIGNED-> */ /* 743*/            isPaging = printSetUIObj.isPaging();
                }
            }
            protected Page getHeader(boolean isPaging, InnerAccountInfo innerAcctInfo)
            {
/* <-MISALIGNED-> */ /* 748*/        HeadFootModel header = new HeadFootModel();
/* <-MISALIGNED-> */ /* 751*/        StyleAttributes saMajorTitle = Styles.getDefaultSA();
/* <-MISALIGNED-> */ /* 752*/        saMajorTitle.setFontSize(14);
/* <-MISALIGNED-> */ /* 753*/        saMajorTitle.setBold(true);
/* <-MISALIGNED-> */ /* 754*/        header.addRow(getPrintPageTitle(), saMajorTitle);
/* <-MISALIGNED-> */ /* 755*/        header.addRow("");
/* <-MISALIGNED-> */ /* 758*/        StringBuffer headStringOne = new StringBuffer();
/* <-MISALIGNED-> */ /* 761*/        headStringOne.append(lblPeriodRange.getBoundLabelText()).append(" ").append(txtPeriodRange.getText()).append("&|");
/* <-MISALIGNED-> */ /* 765*/        headStringOne.append(lblCurrency.getBoundLabelText()).append(" ").append(cboCurrency.getSelectedItem().toString());
/* <-MISALIGNED-> */ /* 768*/        header.addRow(headStringOne.toString());
/* <-MISALIGNED-> */ /* 770*/        StringBuffer headStringTwo = new StringBuffer();
/* <-MISALIGNED-> */ /* 772*/        if(innerAcctInfo != null)
                {
/* <-MISALIGNED-> */ /* 773*/            innerAcctInfo.setDisplayFormat("$number$-$name$");
/* <-MISALIGNED-> */ /* 774*/            headStringTwo.append(EASResource.getString("com.kingdee.eas.fm.fs.client.SubsidiaryLedgerResource.InnerAccount")).append("   ").append(innerAcctInfo).append("&|");
/* <-MISALIGNED-> */ /* 780*/            headStringTwo.append(" ").append("&|").append(" ");
/* <-MISALIGNED-> */ /* 782*/            header.addRow(headStringTwo.toString());
                }
/* <-MISALIGNED-> */ /* 785*/        Page hPage = HeadFootParser.parseModel2HeadFootPage(header);
/* <-MISALIGNED-> */ /* 786*/        return hPage;
            }
            protected Page getFooter()
            {
/* <-MISALIGNED-> */ /* 790*/        HeadFootModel footer = new HeadFootModel();
/* <-MISALIGNED-> */ /* 791*/        String dateString = (new StringBuilder()).append(EASResource.getString((new StringBuilder()).append("com.kingdee.eas.framework.FrameWorkResource.").append(printDateMsg).toString())).append("&[Date]").toString();
/* <-MISALIGNED-> */ /* 795*/        String personString = (new StringBuilder()).append(EASResource.getString((new StringBuilder()).append("com.kingdee.eas.framework.FrameWorkResource.").append(printPersonMsg).toString())).append(SysContext.getSysContext().getCurrentUserInfo().getName()).toString();
/* <-MISALIGNED-> */ /* 798*/        String pageNumber = (new StringBuilder()).append(EASResource.getString((new StringBuilder()).append("com.kingdee.eas.framework.FrameWorkResource.").append(printPageCountMsg).toString())).append("&[Page]/&[PageCount]").toString();
/* <-MISALIGNED-> */ /* 802*/        String footerString = (new StringBuilder()).append(dateString).append("&|").append(personString).append("&|").append(pageNumber).toString();
/* <-MISALIGNED-> */ /* 804*/        StyleAttributes sb = Styles.getDefaultSA();
/* <-MISALIGNED-> */ /* 805*/        footer.addRow(footerString, sb);
/* <-MISALIGNED-> */ /* 806*/        Page fPage = HeadFootParser.parseModel2HeadFootPage(footer);
/* <-MISALIGNED-> */ /* 807*/        return fPage;
            }
            protected static InnerAccountCollection getLeafInnerAccounts(TreePath path)
            {
/* <-MISALIGNED-> */ /* 812*/        DefaultKingdeeTreeNode node = (DefaultKingdeeTreeNode)path.getLastPathComponent();
/* <-MISALIGNED-> */ /* 814*/        InnerAccountCollection coll = getLeafInnerAccounts(null, node);
/* <-MISALIGNED-> */ /* 815*/        return coll;
            }
            private static InnerAccountCollection getLeafInnerAccounts(InnerAccountCollection coll, DefaultKingdeeTreeNode node)
            {
/* <-MISALIGNED-> */ /* 820*/        if(coll == null)
/* <-MISALIGNED-> */ /* 821*/            coll = new InnerAccountCollection();
/* <-MISALIGNED-> */ /* 823*/        if(node.isLeaf() && (node.getUserObject() instanceof InnerAccountInfo))
                {
/* <-MISALIGNED-> */ /* 824*/            coll.add((InnerAccountInfo)node.getUserObject());
                } else
                {
/* <-MISALIGNED-> */ /* 826*/            int i = 0;
/* <-MISALIGNED-> */ /* 826*/            for(int n = node.getChildCount(); i < n; i++)
                    {
/* <-MISALIGNED-> */ /* 827*/                DefaultKingdeeTreeNode leafNode = (DefaultKingdeeTreeNode)node.getChildAt(i);
/* <-MISALIGNED-> */ /* 829*/                getLeafInnerAccounts(coll, leafNode);
                    }
                }
/* <-MISALIGNED-> */ /* 832*/        return coll;
            }
            protected InnerAccountCollection getSelectedInnerAccounts()
            {
/* <-MISALIGNED-> */ /* 836*/        InnerAccountCollection innerAcctColl = new InnerAccountCollection();
/* <-MISALIGNED-> */ /* 837*/        TreePath paths[] = treeList.getSelectionPaths();
/* <-MISALIGNED-> */ /* 839*/        int i = 0;
/* <-MISALIGNED-> */ /* 839*/        for(int n = paths.length; i < n; i++)
/* <-MISALIGNED-> */ /* 840*/            innerAcctColl.addCollection(getLeafInnerAccounts(paths[i]));
/* <-MISALIGNED-> */ /* 842*/        return innerAcctColl;
            }
            protected InnerAccountCollection getAllInnerAccounts()
            {
/* <-MISALIGNED-> */ /* 846*/        InnerAccountCollection innerAcctColl = new InnerAccountCollection();
/* <-MISALIGNED-> */ /* 847*/        TreeModel model = treeList.getModel();
/* <-MISALIGNED-> */ /* 849*/        int i = 0;
/* <-MISALIGNED-> */ /* 849*/        for(int n = model.getChildCount(model.getRoot()); i < n; i++)
                {
/* <-MISALIGNED-> */ /* 850*/            Object childNode = model.getChild(model.getRoot(), i);
/* <-MISALIGNED-> */ /* 851*/            innerAcctColl.addCollection(getLeafInnerAccounts(null, (DefaultKingdeeTreeNode)childNode));
                }
/* <-MISALIGNED-> */ /* 854*/        return innerAcctColl;
            }
            protected void initMultiPrint()
                throws FSException
            {
/* <-MISALIGNED-> */ /* 859*/        multiPrint = new MultiPrint(this);
/* <-MISALIGNED-> */ /* 860*/        multiPrint.getMultiPrintModel().getManager().setParent(this);
/* <-MISALIGNED-> */ /* 862*/        multiPrint.setFrugalPrint(!isPaging);
/* <-MISALIGNED-> */ /* 863*/        if(isPaging)
/* <-MISALIGNED-> */ /* 866*/            tablePrint.getPrintManager().setBodyTopMargin(360F);
/* <-MISALIGNED-> */ /* 868*/        multiPrint.setTable(tablePrint);
                final InnerAccountCollection innerAcctColl;
/* <-MISALIGNED-> */ /* 871*/        if(isPrintAll)
                {
/* <-MISALIGNED-> */ /* 872*/            innerAcctColl = getAllInnerAccounts();
                } else
                {
/* <-MISALIGNED-> */ /* 874*/            innerAcctColl = getSelectedInnerAccounts();
///* <-MISALIGNED-> */ /* 875*/            if(innerAcctColl.size() <= 0)
/* <-MISALIGNED-> */ /* 876*/                throw new FSException(FSException.NOTPRINTALLSELECTROW);
                }
/* <-MISALIGNED-> */ /* 880*/        int i = 0;
/* <-MISALIGNED-> */ /* 880*/        for(int n = innerAcctColl.size(); i < n; i++)
/* <-MISALIGNED-> */ /* 881*/            multiPrint.addPrintData((new Integer(i)).toString());
/* <-MISALIGNED-> */ /* 884*/        multiPrint.setRequestData(new IRequestTableData() {
                    public void requestTableData(String key)
                    {
/* <-MISALIGNED-> */ /* 891*/                tablePrint.removeRows();
/* <-MISALIGNED-> */ /* 892*/                tablePrint.removeColumns();
/* <-MISALIGNED-> */ /* 893*/                tablePrint.removeHeadRows();
/* <-MISALIGNED-> */ /* 896*/                int i = 0;
/* <-MISALIGNED-> */ /* 896*/                for(int n = tblMain.getColumnCount(); i < n; i++)
                        {
/* <-MISALIGNED-> */ /* 897*/                    IColumn oldCol = tblMain.getColumn(i);
/* <-MISALIGNED-> */ /* 899*/                    IColumn newCol = tablePrint.addColumn();
/* <-MISALIGNED-> */ /* 900*/                    newCol.setWidth(oldCol.getWidth());
/* <-MISALIGNED-> */ /* 901*/                    newCol.setKey(oldCol.getKey());
/* <-MISALIGNED-> */ /* 902*/                    newCol.setStyleAttributes(oldCol.getStyleAttributes());
                        }
/* <-MISALIGNED-> */ /* 905*/                IRow headRow = tablePrint.addHeadRow();
/* <-MISALIGNED-> */ /* 906*/                int j = 0;
/* <-MISALIGNED-> */ /* 906*/                for(int n = tablePrint.getColumnCount(); j < n;j++)
                        {
/* <-MISALIGNED-> */ /* 907*/                    IColumn headCol = tablePrint.getColumn(j);
/* <-MISALIGNED-> */ /* 908*/                    String colKey = headCol.getKey();
/* <-MISALIGNED-> */ /* 909*/                    headRow.getCell(colKey).setValue(tblMain.getHeadRow(0).getCell(colKey).getValue());
                        }
/* <-MISALIGNED-> */ /* 914*/                tablePrint.getPrintManager().setHeader(getHeader(isPaging, innerAcctColl.get(Integer.parseInt(key))));
/* <-MISALIGNED-> */ /* 916*/                if(tablePrint.getPrintManager().getFooterModel() == null || tablePrint.getPrintManager().getFooterModel().getRowList().size() == 0 || tablePrint.getPrintManager().getFooterModel().getRowList().get(0) == null || tablePrint.getPrintManager().getFooterModel().getRowList().get(0).toString().equals(""))
/* <-MISALIGNED-> */ /* 920*/                    tablePrint.getPrintManager().setFooter(getFooter());
/* <-MISALIGNED-> */ /* 922*/                copyData(tablePrint, tblMain);
                    }
                    private void copyData(KDTable tablePrint, KDTable tblMain)
                    {
/* <-MISALIGNED-> */ /* 926*/                for(int i = 0; i < tblMain.getRowCount(); i++)
                        {
/* <-MISALIGNED-> */ /* 927*/                    IRow row = tblMain.getRow(i);
/* <-MISALIGNED-> */ /* 928*/                    IRow rowNew = tablePrint.addRow();
/* <-MISALIGNED-> */ /* 929*/                    for(int j = 0; j < tblMain.getColumnCount(); j++)
/* <-MISALIGNED-> */ /* 930*/                        rowNew.getCell(j).setValue(row.getCell(j).getValue());
                        }
                    }
                    private boolean flag;
                    final InnerAccountCollection val$innerAcctColl;
                    final SubsidiaryLedgerUI this$0;
                    
                    {
/* <-MISALIGNED-> */ /* 925*/                this$0 = SubsidiaryLedgerUI.this;
/* <-MISALIGNED-> */ /* 925*/                innerAcctColl = val$innerAcctColl;
/* <-MISALIGNED-> */ /* 925*/                super();
/* <-MISALIGNED-> */ /* 887*/                flag = true;
                    }
        }
);
            }
            public void checkSelected()
            {
/* <-MISALIGNED-> */ /* 938*/        if(tblMain.getRowCount() == 0 || tblMain.getSelectManager().size() == 0)
                {
/* <-MISALIGNED-> */ /* 939*/            MsgBox.showWarning(this, EASResource.getString("com.kingdee.eas.framework.FrameWorkResource.Msg_MustSelected"));
/* <-MISALIGNED-> */ /* 940*/            SysUtil.abort();
                }
            }
            private SubsidiaryLedgerFilterUI filterUI;
            public static final String DEFAULT_TREE_NODE = "DefaultTreeNode";
            public static final String CURRENCY = "currency";
            private static final String resourcePath1 = "com.kingdee.eas.fm.fs.FSClientResource";
            private String resourcePath;
            private static String printDateMsg = "Print_date";
            private static String printPersonMsg = "Print_person";
            private static String printPageCountMsg = "Print_pageCount";
            private boolean isPrintAll;
            private boolean isPaging;
            private MultiPrint multiPrint;
            private KDTable tablePrint;
            private Map balanceMap;
            private BankInfo clearingHouse;
            private boolean refreshTree;
            private static final Logger logger = CoreUIObject.getLogger(SubsidiaryLedgerUI.class);
            Runnable doPrint;
}